home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / itcl1_31.z / itcl1_31 / tcldev / itcl-1.3 / tests / toaster.test < prev    next >
Encoding:
Text File  |  1993-09-23  |  4.0 KB  |  162 lines

  1. #
  2. # Tests for "toaster" example
  3. # ----------------------------------------------------------------------
  4. #   AUTHOR:  Michael J. McLennan       Phone: (215)770-2842
  5. #            AT&T Bell Laboratories   E-mail: aluxpo!mmc@att.com
  6. #
  7. #     SCCS:  @(#)toaster.test    1.3 (7/23/93)
  8. # ----------------------------------------------------------------------
  9. #            Copyright (c) 1993  AT&T  All Rights Reserved
  10. # ======================================================================
  11.  
  12. # ----------------------------------------------------------------------
  13. #  Get toaster classes from "demos" directory.
  14. # ----------------------------------------------------------------------
  15. lappend auto_path ../demos/toasters
  16.  
  17. # ----------------------------------------------------------------------
  18. #  Outlets send bills to an e-mail address.  Determine this address.
  19. # ----------------------------------------------------------------------
  20. if {[info exists env(USER)]} {
  21.     set Owner $env(USER)
  22. } elseif {[info exists env(LOGNAME)]} {
  23.     set Owner $env(LOGNAME)
  24. } else {
  25.     set Owner [exec logname]
  26. }
  27.  
  28. # ----------------------------------------------------------------------
  29. #  TOASTERS
  30. # ----------------------------------------------------------------------
  31. test {Create a toaster and plug it in} {
  32.     global Owner
  33.     Toaster original -heat 1 -outlet [Outlet #auto -owner $Owner]
  34. } {
  35.     $result == "original"
  36. }
  37.  
  38. test {Turn up the heat setting on the toaster} {
  39.     original config -heat 5
  40. } {
  41.     $result == ""
  42. }
  43.  
  44. test {Toast a few slices of bread} {
  45.     original toast 2
  46. } {
  47.     $result == "crumb tray: 25% full"
  48. }
  49.  
  50. test {Clean the toaster} {
  51.     original clean
  52. } {
  53.     $result == "crumb tray: 0% full"
  54. }
  55.  
  56. test {Toast a few slices of bread a few different times} {
  57.     original clean
  58.     original toast 2
  59.     original toast 1
  60. } {
  61.     $result == "crumb tray: 38% full"
  62. }
  63.  
  64. test {Toast too many slices of bread and cause a fire} {
  65.     puts stdout ">>> should say \"== FIRE! FIRE! ==\""
  66.     original clean
  67.     original toast 2
  68.     original toast 2
  69.     original toast 2
  70.     original toast 2
  71. } {
  72.     $result == "crumb tray: 100% full"
  73. }
  74.  
  75. test {Destroy the toaster} {
  76.     original clean
  77.     original toast 2
  78.     original toast 1
  79.     puts stdout ">>> should say \"15 crumbs ... what a mess!\""
  80.     original delete
  81. } {
  82.     $result == ""
  83. }
  84.  
  85. # ----------------------------------------------------------------------
  86. #  SMART TOASTERS
  87. # ----------------------------------------------------------------------
  88. test {Create a toaster and plug it in} {
  89.     global Owner
  90.     SmartToaster deluxe -heat 4 -outlet [Outlet #auto -owner $Owner]
  91. } {
  92.     $result == "deluxe"
  93. }
  94.  
  95. test {Toast a few slices of bread} {
  96.     deluxe toast 2
  97. } {
  98.     $result == "crumb tray: 20% full"
  99. }
  100.  
  101. test {Toast a few slices of bread and look for auto-clean} {
  102.     deluxe clean
  103.     deluxe toast 2
  104.     deluxe toast 2
  105.     deluxe toast 2
  106.     deluxe toast 2
  107.     deluxe toast 2
  108. } {
  109.     $result == "crumb tray: 20% full"
  110. }
  111.  
  112. # ----------------------------------------------------------------------
  113. #  PRODUCT STATISTICS
  114. # ----------------------------------------------------------------------
  115. test {Check statistics gathered by Hazard base class} {
  116.     set tmp [Toaster #auto]
  117.     set stats [Hazard :: report Toaster]
  118.     $tmp delete
  119.     set stats
  120. } {
  121.     $result == "Toaster: 2 produced, 1 active, 1 accidents"
  122. }
  123.  
  124. test {Check statistics gathered by Hazard base class} {
  125.     Hazard :: report SmartToaster
  126. } {
  127.     $result == "SmartToaster: 1 produced, 1 active, 0 accidents"
  128. }
  129.  
  130. test {Destroy all Toasters} {
  131.     foreach toaster [itcl_info objects -isa Toaster] {
  132.         $toaster clean
  133.         $toaster delete
  134.     }
  135. } {
  136.     $result == ""
  137. }
  138.  
  139. test {SmartToasters should have been destroyed along with Toasters} {
  140.     itcl_info objects -class SmartToaster
  141. } {
  142.     $result == ""
  143. }
  144.  
  145. # ----------------------------------------------------------------------
  146. #  OUTLETS
  147. # ----------------------------------------------------------------------
  148. test {Bill all customers for outlet charges} {
  149.     Outlet :: bill
  150.     puts stdout ">>> should send two bills for outlets via e-mail"
  151. } {
  152.     $result == ""
  153. }
  154.  
  155. test {Destroy all outlets} {
  156.     foreach outlet [itcl_info objects -class Outlet] {
  157.         $outlet delete
  158.     }
  159. } {
  160.     $result == ""
  161. }
  162.